package ai_generate_apiCases.general_version;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;


/**
 * @author: Christy Huang
 * @email: huangbixuan@xiaomi.com
 * @since: 2025/05/29
 */

@RestController
@RequestMapping("/ollama")
public class OllamaController {
//    private final OllamaChatModel chatModel;
//
//    @Autowired
//    public OllamaController(OllamaChatModel chatModel) {
//        this.chatModel = chatModel;
//    }


    private ChatClient chatClient;

    // 通过 CharModel 创建一个 ChatClient
    public OllamaController(OllamaChatModel chatModel) {
        this.chatClient = ChatClient.builder(chatModel).build();
    }

    @RequestMapping("/chat")
    public Flux<String> chat(@RequestParam("msg") String msg) {
        Flux<String> result = chatClient.prompt(msg)
                .system("你是一个讲故事的助手")
                .user("暗黑童话故事")
                .stream()
                .content();
        System.out.println("返回结果："+result);
        return result;
    }

//    @RequestMapping("/chat")
//    public Flux<String> chat(@RequestParam("msg") String msg) {
//        Flux<String> result = chatModel.stream(msg);
//        System.out.println("返回结果："+result);
//        return result;
//    }

}
